package it.csi.finregio.finreges.client.validators;

import java.util.Iterator;
import java.util.ResourceBundle;

import javax.servlet.http.HttpServletRequest;

import org.apache.log4j.Logger;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
import org.apache.struts.action.ActionMessages;

import it.crp.crparch.web.struts.validator.CRPStrutsValidator;
import it.crp.logger.PrdLoggerFactory;
import it.csi.finregio.finreges.presentation.form.SchedaForm;

public class SchedaValidator implements CRPStrutsValidator {

	private Logger log = PrdLoggerFactory.getInstance().getLogger("finreges");
	public ActionMessages validate(ActionMapping mapping,
			HttpServletRequest request, ActionForm form) {
		log.info("[SchedaValidator::validate] BEGIN");
		SchedaForm schedaForm = (SchedaForm) form;
		ActionMessages am = new ActionMessages();
		if(schedaForm.getClassificazione().equals("-1")){
			am.add("classificazione",new ActionMessage("alert.field.mandatory",new Object[]{"classificazione"}));
		}
		if(schedaForm.getTitolo()==null || schedaForm.getTitolo().trim().equals("") ){
			am.add("titolo",new ActionMessage("alert.field.mandatory",new Object[]{"titolo"}));
		}
		request.setAttribute("listaErrori", am.get());
		return am;
	}

}
